﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using FluentNHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using WebSite.Data.NH.Repositories.Mappings;
using NHibernate.Cache;

namespace WebSite.Data.NH.Infrastructure
{
    static public class ConnectionHelper
    {
        public static ISessionFactory BuildSessionFactory()
        {
            return GetConfiguration().BuildSessionFactory();
        }

        public static FluentConfiguration GetConfiguration()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Conn")))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<PersonMap>())
                .ExposeConfiguration(x =>
                {
                    x.SetInterceptor(new SqlStatementInterceptor());
                    x.SetProperty("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider");
                    x.SetProperty("cache.use_second_level_cache", "true");
                    x.SetProperty("cache.use_query_cache", "true");
                });
        }
    }
}
